package cc.rengu.igas.mcps.common.dao.impl;


import cc.rengu.igas.mcps.common.dao.TermTxnMapper;
import cc.rengu.igas.mcps.common.entity.TermTxn;
import cc.rengu.oltp.service.common.constant.AppConfigConstant;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.utility.util.DbsUtil;
import cc.rengu.oltp.utility.util.XmlConfigUtil;
import cc.rengu.oltp.utility.util.XmlTreeUtil;
import cc.rengu.utility.cache.UnifiedCache;
import cc.rengu.utility.log.RgLog;
import cc.rengu.utility.log.RgLogger;

/**
 * 终端交易流水表操作实现类.
 */
public class TermTxnMapperImpl implements TermTxnMapper {

    private RgLogger rglog = RgLog.getLogger(this.getClass().getName());
    String dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(AppConfigConstant.DATABASE_CONF_NODE, AppConfigConstant.OLTP_POOL_NAME);

    @Override
    public int insertTermTxn(TermTxn termTxn) throws Exception {

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.OLTP_POOL_NAME);
        }
        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "insertTermTxn");
        int iReturnCode = dbsUtil.dbsExecuteTransactionSql(sqlStr, termTxn, termTxn);
        if (0 != iReturnCode) {
            rglog.error("插入终端流水表失败,商户号:<{}>终端号:<{}>终端流水号:<{}>", termTxn.getMchntNo(), termTxn.getTermNo(), termTxn.getFrontSeqNum());
        }
        return iReturnCode;
    }


}
